package cn.itsource.product.controller;

import cn.itsource.basic.domain.AjaxResult;
import cn.itsource.basic.util.PageList;
import cn.itsource.pet.domain.PetDTO;
import cn.itsource.pet.domain.SearchMasterMessageQuery;
import cn.itsource.pet.domain.StateIdsDto;
import cn.itsource.product.domain.Product;
import cn.itsource.product.domain.ProductDto;
import cn.itsource.product.domain.TProductDetail;
import cn.itsource.product.service.ProductService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("product")
public class ProductController {

    @Autowired
    ProductService productService;

    @PostMapping("pagelist")
    public PageList pagelist(@RequestBody SearchMasterMessageQuery query){
        return productService.pagelist(query);
    }

    @PostMapping("save")
    public AjaxResult save(@RequestBody ProductDto productDto){
        return productService.save(productDto);
    }

    /**
     * 宠物上架的方法
     * @param
     * @return
     */
    @PostMapping("upbutton")
    public AjaxResult upbutton(@RequestBody StateIdsDto stateIdsDto){

        return productService.upbutton(stateIdsDto);
    }

    /**
     * 批量删除的方法
     * @param ids
     * @return
     */
    @PostMapping("deleteBatch")
    public AjaxResult deleteBatch(@RequestBody List<Long> ids){

        return productService.deleteBatch(ids);
    }

    //删除
    @PostMapping("delete")
    public AjaxResult delete(@RequestBody Product product){
        return productService.delete(product);
    }

    //修改回显详情
    @GetMapping("tProductDetail/{id}")
    public AjaxResult tProductDetail(@PathVariable Long id){
        TProductDetail tProductDetail = productService.findById(id);
        return AjaxResult.setResult(tProductDetail);
    }

    //修改
    @PostMapping("EEsave")
    public AjaxResult EEsave(@RequestBody ProductDto productDto){
        return productService.EEsave(productDto);
    }

    @PostMapping("findAll")
    public PageList findAll(@RequestBody SearchMasterMessageQuery query){
        return productService.findAll(query);
    }

    @GetMapping("proFindOne/{id}")
    public Product proFindOne(@PathVariable Long id){
        Product product = productService.proFindOne(id);
        System.out.println(product);
        return product;
    }


}
